<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>更改信息</title>
        <link rel="stylesheet" href="{{ assert(path='admin/component/pear/css/pear.css') | safe }}" />
    </head>
    <body>
    <form class="layui-form" action="">
        <div class="mainBox">
            <div class="main-container">
                <div class="main-container">
                    <div class="layui-form-item">
                        <label class="layui-form-label">父级分类</label>
                        <div class="layui-input-block">
							<select name="pid" lay-verify="">
								<option value="0">作为顶级分类</option>
                                {% if cate_list %}
                                    {% for cate_item in cate_list %}
                                        {% if cate_item.pid == 0 and cate_item.id != data.id %}
                                            {% if data.pid == cate_item.id %}
                                                <option value="{{ cate_item.id }}" selected>{{ cate_item.name }}</option>
                                            {% else %}
                                                <option value="{{ cate_item.id }}">{{ cate_item.name }}</option>
                                            {% endif %}
                                        {% endif %}
                                    {% endfor %}
                                {% endif %}
							</select>
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">分类名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" 
                                value="{{ data.name }}" 
                                lay-verify="title" autocomplete="off" 
                                placeholder="请输入分类名称" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">分类标识</label>
                        <div class="layui-input-block">
                            <input type="text" name="slug" 
                                value="{{ data.slug }}" 
                                lay-verify="title" autocomplete="off" 
                                placeholder="请输入分类标识" class="layui-input">
                        </div>
                    </div>
    
                    <div class="layui-form-item">
                        <label class="layui-form-label">描述</label>
                        <div class="layui-input-block">
                            <textarea name="desc" placeholder="请输入描述" class="layui-textarea">{{ data.desc }}</textarea>
                        </div>
                    </div>
    
                    <div class="layui-form-item">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-block">
                            <input type="text" name="sort" value="{{ data.sort }}" 
                                lay-verify="title" autocomplete="off" 
                                placeholder="请输入排序" class="layui-input">
                        </div>
                    </div>
    
                    <div class="layui-form-item">
                        <label class="layui-form-label">列表模板</label>
                        <div class="layui-input-block">
							<select name="list_tpl" lay-verify="">
                                {% for list_tpl in list_tpls %}
                                    {% if data.list_tpl == list_tpl %}
                                        <option value="{{ list_tpl }}" selected>{{ list_tpl }}</option>
                                    {% else %}
                                        <option value="{{ list_tpl }}">{{ list_tpl }}</option>
                                    {% endif %}
                                {% endfor %}
							</select>
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">详情模板</label>
                        <div class="layui-input-block">
							<select name="view_tpl" lay-verify="">
                                {% for view_tpl in view_tpls %}
                                    {% if data.view_tpl == view_tpl %}
								        <option value="{{ view_tpl }}" selected>{{ view_tpl }}</option>
                                    {% else %}
                                        <option value="{{ view_tpl }}">{{ view_tpl }}</option>
                                    {% endif %}
                                {% endfor %}
							</select>
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            {% if data.status == 1 %}
                                <input type="radio" name="status" value="1" title="启用" checked>
                                <input type="radio" name="status" value="0" title="禁用">
                            {% else %}
                                <input type="radio" name="status" value="1" title="启用">
                                <input type="radio" name="status" value="0" title="禁用" checked>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="cate-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>

    <script src="{{ assert(path='admin/component/layui/layui.js') | safe }}"></script>
    <script src="{{ assert(path='admin/component/pear/pear.js') | safe }}"></script>
    <script>
    layui.use(['form','jquery'],function(){
        let form = layui.form;
        let $ = layui.jquery;

        form.on('submit(cate-save)', function(data) {
            $.ajax({
                url: "{{ url_for(name='admin.cate-update') | safe }}?id={{ data.id }}",
                data: data.field,
                dataType: 'json',
                type: 'post',
                success: function(result) {
                    if (result.code == 0) {
                        layer.msg(result.message, {icon:1,time:1000}, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("cate-table");
                        });
                    } else {
                        layer.msg(result.message, {icon:2,time:1000});
                    }
                }
            });

            return false;
        });
    })
    </script>
    </body>
</html>
